from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

class UserManager(BaseUserManager):
    def create_user(self, email, password):
        email = self.normalize_email(email)
        user:UserAccount = self.model(email=email)
        user.set_password(password)
        user.save()
        return user


# Create your models here.
class UserAccount(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(max_length=255, default="new user")
    email = models.EmailField(max_length=255, unique=True)
    password = models.CharField(max_length=255)
    phone = models.CharField(max_length=22,default="")
    avator = models.BinaryField(default=b"")
    objects = UserManager()
    USERNAME_FIELD = 'email'